package com.shuzijun.blog;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.shuzijun.blog.pojo.Users;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class TestPOI {

    public List<Users> getUsers(){
        List<Users> users = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Users user=new Users();
            user.setId(String.valueOf(i));
            user.setName("xiaotu"+i);
            user.setAge(20+i);
            user.setBir(new Date());
            users.add(user);
        }
        return users;
    }



    @Test
    public  void testExport() throws IOException {
        List<Users> users = getUsers();
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("用户信息列表", "用户信息"), Users.class, users);
        FileOutputStream fileOutputStream = new FileOutputStream("C:/Users/Administrator/Desktop/test.xlsx");
        workbook.write(fileOutputStream);
        fileOutputStream.close();
        workbook.close();
    }
}
